package interceptor;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import java.util.Map;


/**
 * Created by hadoop on 17-6-26.
 * 使用拦截器实现权限控制
 */
public class AuthorityInterceptor extends AbstractInterceptor{
    @Override
    public String intercept(ActionInvocation actionInvocation) throws Exception {
        ActionContext context = actionInvocation.getInvocationContext();
        Map session = context.getSession();
        String user = (String) session.get("user");
        if(user != null && user.equals("1")){
            return actionInvocation.invoke();
        }else{
            context.put("tip","请先登录");
            return "login";
        }

    }
}
